package com.grace.cms.common.model.support;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson2.annotation.JSONField;
import com.github.pagehelper.PageInfo;

/**
 * @author grace
 *
 *         分页数据
 */
public class PageData<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    /** 总记录数 */
    private long total;
    /** 消息状态码 */
    private int code;
    /** 当前页 */
    private long pageNum;
    /** 每页数据量 */
    private long pageSize;
    /** 总页数 */
    private long pages;
    /** 列表数据 */
    private List<T> rows;
    @JSONField(serialize = false)
    private Map<String, List<T>> timeLineData;
    public long getPages() {
        return pages;
    }

    public void setPages(long pages) {
        this.pages = pages;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public long getPageNum() {
        return pageNum;
    }

    public void setPageNum(long pageNum) {
        this.pageNum = pageNum;
    }

    public long getPageSize() {
        return pageSize;
    }

    public void setPageSize(long pageSize) {
        this.pageSize = pageSize;
    }

    public PageData() {
        super();
    }

    public Map<String, List<T>> getTimeLineData() {
        return timeLineData;
    }

    public void setTimeLineData(Map<String, List<T>> timeLineData) {
        this.timeLineData = timeLineData;
    }

    public List<T> getRows() {
        return rows;
    }

    public void setRows(List<T> rows) {
        this.rows = rows;
    }

    public PageData(long total, int code, long pages, long pageNum, long pageSize, List<T> rows) {
        super();
        this.total = total;
        this.code = code;
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.pages = pages;
        this.rows = rows;
    }

  
    /**
     * 响应请求分页数据 普通分页
     *
     * @param list 分页列表数据
     * @param code 状态码
     * @return 返回分页数据对象
     */
    public static <T> PageData<T> getData(List<T> list, int code) {
        PageInfo<T> page = new PageInfo<>(list);
        PageData<T> rspData = new PageData<>(
                page.getTotal(), 
                code, 
                page.getPages(), 
                page.getPageNum(), 
                page.getPageSize(),
                list
        );
        return rspData;
    }

}
